package com.xu.ai.chatclient.util;

import java.util.Objects;

import org.springframework.ai.model.ResponseMetadata;

import com.xu.ai.chatclient.exception.AiException;

/**
 * ai rest请求工具类
 *
 * @author xuguan
 * @since 2025/10/17
 */
public class AiRestUtil {

	public static void checkResponseMetadata(ResponseMetadata metadata) {
		final String taskStatus = metadata.getRequired("taskStatus");
		if (!Objects.equals(taskStatus, "SUCCEEDED")) {
			final String code = metadata.get("code");
			final String message = metadata.get("message");
			throw new AiException(code, message);
		}
	}

	public enum ModelUri {

		OPENAI("/compatible-mode/v1/chat/completions"), CHAT("/api/v1/services/aigc/text-generation/generation"),
		MULTIMODAL("/api/v1/services/aigc/multimodal-generation/generation"),
		TEXT2IMAGE("/api/v1/services/aigc/text2image/image-synthesis"),
		IMAGE2IMAGE("/api/v1/services/aigc/image2image/image-synthesis"),
		VIDEO("/api/v1/services/aigc/video-generation/video-synthesis"),
		IMAGE2VIDEO("/api/v1/services/aigc/image2video/video-synthesis"),;

		private final String uri;

		ModelUri(String uri) {
			this.uri = uri;
		}

		public String getUri() {
			return uri;
		}

	}

}
